/*
 * Copyright 2020-2021 redragon.dongbin
 *
 * This file is part of redragon-erp/赤龙ERP.

 * redragon-erp/赤龙ERP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.

 * redragon-erp/赤龙ERP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with redragon-erp/赤龙ERP.  If not, see <https://www.gnu.org/licenses/>.
 */
package com.erp.ledger.balance.controller;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.redragon.framework.springmvc.ControllerSupport;
import org.apache.commons.lang.StringUtils;
import org.hibernate.exception.ConstraintViolationException;
import org.redragon.commons.lang.JavaReflect;
import org.redragon.commons.lang.Times;
import org.redragon.framework.hibernate.data.RDDataBox;
import org.redragon.framework.hibernate.data.SnowFlake;
import org.redragon.framework.hibernate.model.Pages;
import org.redragon.framework.util.JsonDataUtil;
import org.redragon.framework.util.JsonUtil;
import org.redragon.framework.util.ShiroUtil;

import com.erp.dataset.service.DatasetCommonService;
import com.erp.ledger.account.dao.model.GLCodeCombinations;
import com.erp.ledger.account.dao.model.GLLedger;
import com.erp.ledger.account.service.GLCodeCombinationsService;
import com.erp.ledger.account.service.GLLedgerService;
import com.erp.ledger.balance.dao.model.GLBalance;
import com.erp.ledger.balance.dao.model.GLBalanceCO;
import com.erp.ledger.balance.service.GLBalanceService;
import com.erp.ledger.balance.util.GLBalanceUtil;
import com.erp.masterdata.calendar.dao.model.MdFinanceCalendarPeriod;
import com.erp.masterdata.calendar.dao.model.MdFinanceCalendarPeriodCO;
import com.erp.masterdata.calendar.service.MdFinanceCalendarPeriodService;
import com.erp.masterdata.common.service.MasterDataCommonService;
import com.erp.masterdata.eco.service.MasterDataEcoService;
import com.erp.masterdata.expense.dao.model.MdExpenseItem;
import com.erp.masterdata.subject.dao.model.MdFinanceSubject;
import com.erp.masterdata.subject.service.MdFinanceSubjectService;

@Controller
@RequestMapping("/web/gLTable")
public class GLTableWebController extends ControllerSupport{
    
    //日志处理
    private Logger logger = LoggerFactory.getLogger(GLTableWebController.class);
    
    //服务层注入
    @Autowired
    private GLBalanceService gLBalanceService;
    @Autowired
    private DatasetCommonService datasetCommonService;
    @Autowired
    private MasterDataCommonService masterDataCommonService;
    @Autowired
    private GLCodeCombinationsService glCodeCombinationsService;
    @Autowired
    private MdFinanceCalendarPeriodService mdFinanceCalendarPeriodService;
    @Autowired
    private GLLedgerService glLedgerService;
    @Autowired
    private MdFinanceSubjectService mdFinanceSubjectService;
    
    @Override
    public String getExceptionRedirectUrl() {
        return this.getFormatRedirectUrl("getList");
    }
    
    
    
    /**
     * 
     * @description 结账跳转页面
     * @date 2021年2月4日
     * @author dongbin
     * @param model
     * @param attr
     * @return
     * @return String
     *
     */
    @RequestMapping("beforeGLTable")
    public String beforeGLTable(Model model, RedirectAttributes attr) {
        
        //分类账
        GLLedger glLedger = this.glLedgerService.getPrimaryGLLedgerByLegal(ShiroUtil.getLegalCode());
        //期间
        Pages pages1 = new Pages();
        pages1.setPage(1);
        pages1.setMax(100);
        MdFinanceCalendarPeriodCO mdFinanceCalendarPeriodCO = new MdFinanceCalendarPeriodCO();
        mdFinanceCalendarPeriodCO.setCalendarCode(glLedger.getCalendarCode());
        mdFinanceCalendarPeriodCO.setPeriodStatus("OPEN");
        List<MdFinanceCalendarPeriod> calendarPeriodList = this.mdFinanceCalendarPeriodService.getPeriodListByCalendarCode(pages1, mdFinanceCalendarPeriodCO);
        
        //页面属性设置
        model.addAttribute("calendarPeriodList", calendarPeriodList);
        
        return "basic.jsp?content=gLTable/glTable";
    }
    
        
    
    /**
     * 
     * @description 跳转科目余额表
     * @date 2021年2月9日
     * @author dongbin
     * @param model
     * @return
     * @return String
     *
     */
    @RequestMapping("getGLAccountBalanceTable")
    public String getGLAccountBalanceTable(String periodName, Model model) {
        
        //获取当前时间的期间
        if(StringUtils.isBlank(periodName)) {
            Times times = new Times();
            MdFinanceCalendarPeriod period = this.mdFinanceCalendarPeriodService.getPeriodNameByDate(times.getJavaDate());
            periodName = period.getPeriodName();
        }
        
        //页面属性设置
        model.addAttribute("periodName", periodName);

        
        return "gLTable/accountBalance";
    }
    
    
    
    /**
     * 
     * @description 科目余额表获取json数据
     * @date 2021年2月9日
     * @author dongbin
     * @param model
     * @return
     * @return String
     *
     */
    @RequestMapping("getGLAccountBalanceTableJson")
    @ResponseBody
    public String getGLAccountBalanceTableJson(String periodName, Model model) {
        
        String json = "[{"
                + "'name': '科目余额表',"
                + "'index': 0,"
                + "'status': 1,'order': 0,"
                + "'defaultColWidth': 100,"
                + "'config': {"
                + "'merge':{'0_0': {'r': 0,'c': 0,'rs': 2,'cs': 1},'0_1': {'r': 0,'c': 1,'rs': 2,'cs': 1},'0_2': {'r': 0,'c': 2,'rs': 1,'cs': 2},"
                + "'0_4': {'r': 0,'c': 4,'rs': 1,'cs': 2},'0_6': {'r': 0,'c': 6,'rs': 1,'cs': 2},},"
                + "'rowlen':{}, "
                + "'columnlen':{}, "
                + "},"
                + "'celldata': ["
                + "{'r':0,'c':0,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'科目编码','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 0, 'rs': 2, 'cs': 1 }},"
                + "{'r':0,'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'科目名称','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 1, 'rs': 2, 'cs': 1 }},"
                + "{'r':0,'c':2,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'期初余额','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 2, 'rs': 1, 'cs': 2 }},"
                + "{'r':0,'c':3,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 2, }},"
                + "{'r':0,'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'本期发生额','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 4, 'rs': 1, 'cs': 2 }},"
                + "{'r':0,'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 4, }},"
                + "{'r':0,'c':6,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'期末余额','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 6, 'rs': 1, 'cs': 2 }},"
                + "{'r':0,'c':7,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 6, }},"
               
                + "{'r':1,'c':0,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 0, }},"
                + "{'r':1,'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 1, }},"
                + "{'r':1,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'借方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':3,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'贷方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'借方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'贷方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':6,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'借方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':7,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'贷方','ct':{'fa':'General','t':'s'},'m':''}},";

        //期初借方贷方
        BigDecimal beginDrSum = new BigDecimal(0D);
        BigDecimal beginCrSum = new BigDecimal(0D);
        //本期发生借方贷方
        BigDecimal periodDrSum = new BigDecimal(0D);
        BigDecimal periodCrSum = new BigDecimal(0D);
        //期末借方贷方
        BigDecimal endDrSum = new BigDecimal(0D);
        BigDecimal endCrSum = new BigDecimal(0D);
        
        //获取主分类账
        GLLedger glLedger = this.glLedgerService.getPrimaryGLLedgerByLegal(ShiroUtil.getLegalCode());
        //获取一级科目
        List<MdFinanceSubject> subjectList = this.mdFinanceSubjectService.getMdFinanceSubjectListByGrade(2);
        //获取科目在主分类账中的段值位置
        int segmentNum = this.glLedgerService.getSegmentNumByLegal(ShiroUtil.getLegalCode(), "SEGMENT_SUBJECT");
        int index = 1;
        //循环获取每个一级科目的所有下级科目
        for(MdFinanceSubject subject: subjectList) {
            index++;
            //期初借方贷方
            BigDecimal beginDr = new BigDecimal(0D);
            BigDecimal beginCr = new BigDecimal(0D);
            //本期发生借方贷方
            BigDecimal periodDr = new BigDecimal(0D);
            BigDecimal periodCr = new BigDecimal(0D);
            //期末借方贷方
            BigDecimal endDr = new BigDecimal(0D);
            BigDecimal endCr = new BigDecimal(0D);
            
            List<GLCodeCombinations> glCodeCombinations = this.glCodeCombinationsService.getGLCodeCombinationsBySegmentValue(String.valueOf(segmentNum), subject.getSubjectCode(), true);
            //循环所有下级科目获取下级科目的平衡表   
            for(int a=0;a<glCodeCombinations.size();a++) {
                List<GLBalance> glBalanceList = this.gLBalanceService.getGLBalanceListBySubject(glLedger.getLedgerCode(), periodName, glCodeCombinations.get(a).getCodeCombinationCode());
                //循环计算科目余额表
                for(int b=0;b<glBalanceList.size();b++) {
                    //累加期初
                    if(b==0) {
                        beginDr = new BigDecimal(glBalanceList.get(b).getBeginDr()).add(beginDr);
                        beginCr = new BigDecimal(glBalanceList.get(b).getBeginCr()).add(beginCr);
                    }
                    //累加本期发生
                    periodDr = new BigDecimal(glBalanceList.get(b).getPeriodDr()).add(periodDr);
                    periodCr = new BigDecimal(glBalanceList.get(b).getPeriodCr()).add(periodCr);
                }
            }
            //累加期末
            endDr = beginDr.add(periodDr);
            endCr = beginCr.add(periodCr);
            
            //重新计算期初借贷方
            if(beginDr.doubleValue()>=beginCr.doubleValue()) {
                beginDr = beginDr.subtract(beginCr);
                beginCr = new BigDecimal(0D);
            }else {
                beginCr = beginCr.subtract(beginDr);
                beginDr = new BigDecimal(0D);
            }
            
            //重新计算期末借贷方
            if(endDr.doubleValue()>=endCr.doubleValue()) {
                endDr = endDr.subtract(endCr);
                endCr = new BigDecimal(0D);
            }else {
                endCr = endCr.subtract(endDr);
                endDr = new BigDecimal(0D);
            }
            
            //计算汇总
            beginDrSum = beginDrSum.add(beginDr);
            beginCrSum = beginCrSum.add(beginCr);
            periodDrSum = periodDrSum.add(periodDr);
            periodCrSum = periodCrSum.add(periodCr);
            endDrSum = endDrSum.add(endDr);
            endCrSum = endCrSum.add(endCr);
            
            //组合json
            json = json + "{'r':"+index+",'c':0,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'"+subject.getSubjectCode()+"','ct':{'fa':'General','t':'s'},'m':''}},";
            json = json + "{'r':"+index+",'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'"+subject.getSubjectName()+"','ct':{'fa':'General','t':'s'},'m':''}},";
            json = json + "{'r':"+index+",'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+beginDr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':3,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+beginCr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+periodDr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+periodCr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':6,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+endDr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':7,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+endCr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        }
        
        //组合汇总json
        index++;
        json = json + "{'r':"+index+",'c':0,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':"+index+",'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'合计','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':"+index+",'c':2,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+beginDrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':3,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+beginCrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+periodDrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+periodCrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':6,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+endDrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':7,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+endCrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        json = json + "], ";
        json = json + "}]";
        
        return json;
    }
    
    
    
    /**
     * 
     * @description 跳转科目余额明细表
     * @date 2021年2月9日
     * @author dongbin
     * @param model
     * @return
     * @return String
     *
     */
    @RequestMapping("getGLAccountBalanceDetailTable")
    public String getGLAccountBalanceDetailTable(String periodName, Model model) {
        
        //获取当前时间的期间
        if(StringUtils.isBlank(periodName)) {
            Times times = new Times();
            MdFinanceCalendarPeriod period = this.mdFinanceCalendarPeriodService.getPeriodNameByDate(times.getJavaDate());
            periodName = period.getPeriodName();
        }
        
        //页面属性设置
        model.addAttribute("periodName", periodName);
        
        return "gLTable/accountBalanceDetail";
    }
    
    
    
    /**
     * 
     * @description 科目余额明细表获取json数据
     * @date 2021年2月9日
     * @author dongbin
     * @param model
     * @return
     * @return String
     *
     */
    @RequestMapping("getGLAccountBalanceDetailTableJson")
    @ResponseBody
    public String getGLAccountBalanceDetailTableJson(String periodName, String subjectCode, Model model) {
        
        String json = "[{"
                + "'name': '科目余额明细表',"
                + "'index': 0,"
                + "'status': 1,'order': 0,"
                + "'defaultColWidth': 100,"
                + "'config': {"
                + "'merge':{'0_0': {'r': 0,'c': 0,'rs': 2,'cs': 1},'0_1': {'r': 0,'c': 1,'rs': 2,'cs': 1},'0_2': {'r': 0,'c': 2,'rs': 1,'cs': 2},"
                + "'0_4': {'r': 0,'c': 4,'rs': 1,'cs': 2},'0_6': {'r': 0,'c': 6,'rs': 1,'cs': 2},},"
                + "'rowlen':{}, "
                + "'columnlen':{'0': 300, '1': 400}, "
                + "},"
                + "'celldata': ["
                + "{'r':0,'c':0,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'科目编码','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 0, 'rs': 2, 'cs': 1 }},"
                + "{'r':0,'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'科目名称','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 1, 'rs': 2, 'cs': 1 }},"
                + "{'r':0,'c':2,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'期初余额','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 2, 'rs': 1, 'cs': 2 }},"
                + "{'r':0,'c':3,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 2, }},"
                + "{'r':0,'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'本期发生额','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 4, 'rs': 1, 'cs': 2 }},"
                + "{'r':0,'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 4, }},"
                + "{'r':0,'c':6,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'期末余额','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 6, 'rs': 1, 'cs': 2 }},"
                + "{'r':0,'c':7,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 6, }},"
               
                + "{'r':1,'c':0,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 0, }},"
                + "{'r':1,'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 1, }},"
                + "{'r':1,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'借方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':3,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'贷方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'借方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'贷方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':6,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'借方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':7,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'贷方','ct':{'fa':'General','t':'s'},'m':''}},";

        //期初借方贷方
        BigDecimal beginDrSum = new BigDecimal(0D);
        BigDecimal beginCrSum = new BigDecimal(0D);
        //本期发生借方贷方
        BigDecimal periodDrSum = new BigDecimal(0D);
        BigDecimal periodCrSum = new BigDecimal(0D);
        //期末借方贷方
        BigDecimal endDrSum = new BigDecimal(0D);
        BigDecimal endCrSum = new BigDecimal(0D);
        
        //获取主分类账
        GLLedger glLedger = this.glLedgerService.getPrimaryGLLedgerByLegal(ShiroUtil.getLegalCode());
        //获取科目在主分类账中的段值位置
        int segmentNum = this.glLedgerService.getSegmentNumByLegal(ShiroUtil.getLegalCode(), "SEGMENT_SUBJECT");
        int index = 1;
        
        List<GLCodeCombinations> glCodeCombinations = this.glCodeCombinationsService.getGLCodeCombinationsBySegmentValue(String.valueOf(segmentNum), subjectCode, true);
        //循环所有下级科目获取下级科目的平衡表   
        for(int a=0;a<glCodeCombinations.size();a++) {
            //期初借方贷方
            BigDecimal beginDr = new BigDecimal(0D);
            BigDecimal beginCr = new BigDecimal(0D);
            //本期发生借方贷方
            BigDecimal periodDr = new BigDecimal(0D);
            BigDecimal periodCr = new BigDecimal(0D);
            //期末借方贷方
            BigDecimal endDr = new BigDecimal(0D);
            BigDecimal endCr = new BigDecimal(0D);
            
            index++;
            
            List<GLBalance> glBalanceList = this.gLBalanceService.getGLBalanceListBySubject(glLedger.getLedgerCode(), periodName, glCodeCombinations.get(a).getCodeCombinationCode());
            //循环计算科目余额表
            for(int b=0;b<glBalanceList.size();b++) {
                //累加期初
                if(b==0) {
                    beginDr = new BigDecimal(glBalanceList.get(b).getBeginDr()).add(beginDr);
                    beginCr = new BigDecimal(glBalanceList.get(b).getBeginCr()).add(beginCr);
                }
                //累加本期发生
                periodDr = new BigDecimal(glBalanceList.get(b).getPeriodDr()).add(periodDr);
                periodCr = new BigDecimal(glBalanceList.get(b).getPeriodCr()).add(periodCr);
            }
            
            //累加期末
            endDr = beginDr.add(periodDr);
            endCr = beginCr.add(periodCr);
            
//            JavaReflect reflect = new JavaReflect(glCodeCombinations.get(a).getClass());
//            reflect.setObject(glCodeCombinations.get(a));
//            String segmentTemp = (String)reflect.doMethod("getSegment"+segmentNum, null, null);
            
            //重新计算期初借贷方
            if(beginDr.doubleValue()>=beginCr.doubleValue()) {
                beginDr = beginDr.subtract(beginCr);
                beginCr = new BigDecimal(0D);
            }else {
                beginCr = beginCr.subtract(beginDr);
                beginDr = new BigDecimal(0D);
            }
            
            //重新计算期末借贷方
            if(endDr.doubleValue()>=endCr.doubleValue()) {
                endDr = endDr.subtract(endCr);
                endCr = new BigDecimal(0D);
            }else {
                endCr = endCr.subtract(endDr);
                endDr = new BigDecimal(0D);
            }
            
            //计算汇总
            beginDrSum = beginDrSum.add(beginDr);
            beginCrSum = beginCrSum.add(beginCr);
            periodDrSum = periodDrSum.add(periodDr);
            periodCrSum = periodCrSum.add(periodCr);
            endDrSum = endDrSum.add(endDr);
            endCrSum = endCrSum.add(endCr);
            
            //组合json
            json = json + "{'r':"+index+",'c':0,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'"+this.glCodeCombinationsService.getGLCodeCombinationsSegment(glCodeCombinations.get(a).getCodeCombinationCode())+"','ct':{'fa':'General','t':'s'},'m':''}},";
            json = json + "{'r':"+index+",'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'"+this.glCodeCombinationsService.getGLCodeCombinationsSegmentDesc(glCodeCombinations.get(a).getCodeCombinationCode())+"','ct':{'fa':'General','t':'s'},'m':''}},";
            json = json + "{'r':"+index+",'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+beginDr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':3,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+beginCr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+periodDr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+periodCr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':6,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+endDr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':7,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+endCr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            
        }
        
        //组合汇总json
        index++;
        json = json + "{'r':"+index+",'c':0,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':"+index+",'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'合计','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':"+index+",'c':2,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+beginDrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':3,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+beginCrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+periodDrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+periodCrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':6,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+endDrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':7,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+endCrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        json = json + "], ";
        json = json + "}]";
        
        return json;
    }
    
    
    
    /**
     * 
     * @description 跳转试算平衡表
     * @date 2021年2月9日
     * @author dongbin
     * @param model
     * @return
     * @return String
     *
     */
    @RequestMapping("getGLAccountBalanceTestTable")
    public String getGLAccountBalanceTestTable(String periodName, Model model) {
        
        //获取当前时间的期间
        if(StringUtils.isBlank(periodName)) {
            Times times = new Times();
            MdFinanceCalendarPeriod period = this.mdFinanceCalendarPeriodService.getPeriodNameByDate(times.getJavaDate());
            periodName = period.getPeriodName();
        }
        
        //页面属性设置
        model.addAttribute("periodName", periodName);
        
        return "gLTable/accountBalanceTest";
    }
    
    
    
    /**
     * 
     * @description 试算平衡表获取json数据
     * @date 2021年2月9日
     * @author dongbin
     * @param model
     * @return
     * @return String
     *
     */
    @RequestMapping("getGLAccountBalanceTestTableJson")
    @ResponseBody
    public String getGLAccountBalanceTestTableJson(String periodName, Model model) {
        
        String json = "[{"
                + "'name': '试算平衡表',"
                + "'index': 0,"
                + "'status': 1,'order': 0,"
                + "'defaultColWidth': 100,"
                + "'config': {"
                + "'merge':{'0_0': {'r': 0,'c': 0,'rs': 2,'cs': 1},'0_1': {'r': 0,'c': 1,'rs': 2,'cs': 1},'0_2': {'r': 0,'c': 2,'rs': 1,'cs': 2},"
                + "'0_4': {'r': 0,'c': 4,'rs': 1,'cs': 2},'0_6': {'r': 0,'c': 6,'rs': 1,'cs': 2},},"
                + "'rowlen':{}, "
                + "'columnlen':{}, "
                + "},"
                + "'celldata': ["
                + "{'r':0,'c':0,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'科目编码','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 0, 'rs': 2, 'cs': 1 }},"
                + "{'r':0,'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'科目名称','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 1, 'rs': 2, 'cs': 1 }},"
                + "{'r':0,'c':2,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'期初余额','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 2, 'rs': 1, 'cs': 2 }},"
                + "{'r':0,'c':3,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 2, }},"
                + "{'r':0,'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'本期发生额','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 4, 'rs': 1, 'cs': 2 }},"
                + "{'r':0,'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 4, }},"
                + "{'r':0,'c':6,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'期末余额','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 6, 'rs': 1, 'cs': 2 }},"
                + "{'r':0,'c':7,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 6, }},"
               
                + "{'r':1,'c':0,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 0, }},"
                + "{'r':1,'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''},'mc': {'r': 0, 'c': 1, }},"
                + "{'r':1,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'借方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':3,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'贷方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'借方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'贷方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':6,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'借方','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':1,'c':7,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'贷方','ct':{'fa':'General','t':'s'},'m':''}},";

        //期初借方贷方
        BigDecimal beginDrSum = new BigDecimal(0D);
        BigDecimal beginCrSum = new BigDecimal(0D);
        //本期发生借方贷方
        BigDecimal periodDrSum = new BigDecimal(0D);
        BigDecimal periodCrSum = new BigDecimal(0D);
        //期末借方贷方
        BigDecimal endDrSum = new BigDecimal(0D);
        BigDecimal endCrSum = new BigDecimal(0D);
        
        //获取主分类账
        GLLedger glLedger = this.glLedgerService.getPrimaryGLLedgerByLegal(ShiroUtil.getLegalCode());
        //获取一级科目
        List<MdFinanceSubject> subjectList = this.mdFinanceSubjectService.getMdFinanceSubjectListGTGrade(2);
        //获取科目在主分类账中的段值位置
        int segmentNum = this.glLedgerService.getSegmentNumByLegal(ShiroUtil.getLegalCode(), "SEGMENT_SUBJECT");
        int index = 1;
        //循环获取每个一级科目的所有下级科目
        for(MdFinanceSubject subject: subjectList) {
            index++;
            //期初借方贷方
            BigDecimal beginDr = new BigDecimal(0D);
            BigDecimal beginCr = new BigDecimal(0D);
            //本期发生借方贷方
            BigDecimal periodDr = new BigDecimal(0D);
            BigDecimal periodCr = new BigDecimal(0D);
            //期末借方贷方
            BigDecimal endDr = new BigDecimal(0D);
            BigDecimal endCr = new BigDecimal(0D);
            
            List<GLCodeCombinations> glCodeCombinations = this.glCodeCombinationsService.getGLCodeCombinationsBySegmentValue(String.valueOf(segmentNum), subject.getSubjectCode(), true);
            //循环所有下级科目获取下级科目的平衡表   
            for(int a=0;a<glCodeCombinations.size();a++) {
                List<GLBalance> glBalanceList = this.gLBalanceService.getGLBalanceListBySubject(glLedger.getLedgerCode(), periodName, glCodeCombinations.get(a).getCodeCombinationCode());
                //循环计算科目余额表
                for(int b=0;b<glBalanceList.size();b++) {
                    //累加期初
                    if(b==0) {
                        beginDr = new BigDecimal(glBalanceList.get(b).getBeginDr()).add(beginDr);
                        beginCr = new BigDecimal(glBalanceList.get(b).getBeginCr()).add(beginCr);
                    }
                    //累加本期发生
                    periodDr = new BigDecimal(glBalanceList.get(b).getPeriodDr()).add(periodDr);
                    periodCr = new BigDecimal(glBalanceList.get(b).getPeriodCr()).add(periodCr);
                }
            }
            //累加期末
            endDr = beginDr.add(periodDr);
            endCr = beginCr.add(periodCr);
            
            //重新计算期初借贷方
            if(beginDr.doubleValue()>=beginCr.doubleValue()) {
                beginDr = beginDr.subtract(beginCr);
                beginCr = new BigDecimal(0D);
            }else {
                beginCr = beginCr.subtract(beginDr);
                beginDr = new BigDecimal(0D);
            }
            
            //重新计算期末借贷方
            if(endDr.doubleValue()>=endCr.doubleValue()) {
                endDr = endDr.subtract(endCr);
                endCr = new BigDecimal(0D);
            }else {
                endCr = endCr.subtract(endDr);
                endDr = new BigDecimal(0D);
            }
            
            //计算汇总
            beginDrSum = beginDrSum.add(beginDr);
            beginCrSum = beginCrSum.add(beginCr);
            periodDrSum = periodDrSum.add(periodDr);
            periodCrSum = periodCrSum.add(periodCr);
            endDrSum = endDrSum.add(endDr);
            endCrSum = endCrSum.add(endCr);
            
            //组合json
            json = json + "{'r':"+index+",'c':0,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'"+subject.getSubjectCode()+"','ct':{'fa':'General','t':'s'},'m':''}},";
            json = json + "{'r':"+index+",'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'"+subject.getSubjectName()+"','ct':{'fa':'General','t':'s'},'m':''}},";
            json = json + "{'r':"+index+",'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+beginDr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':3,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+beginCr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+periodDr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+periodCr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':6,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+endDr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
            json = json + "{'r':"+index+",'c':7,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+endCr+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        }
        
        //组合汇总json
        index++;
        json = json + "{'r':"+index+",'c':0,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':"+index+",'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'合计','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':"+index+",'c':2,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+beginDrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':3,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+beginCrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+periodDrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+periodCrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':6,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+endDrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':"+index+",'c':7,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+endCrSum+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        json = json + "], ";
        json = json + "}]";
        
        return json;
    }
    
    
    
    /**
     * 
     * @description 跳转资产负债表
     * @date 2021年2月9日
     * @author dongbin
     * @param model
     * @return
     * @return String
     *
     */
    @RequestMapping("getGLALBalanceTable")
    public String getGLALBalanceTable(String periodName, Model model) {
        
        //获取当前时间的期间
        if(StringUtils.isBlank(periodName)) {
            Times times = new Times();
            MdFinanceCalendarPeriod period = this.mdFinanceCalendarPeriodService.getPeriodNameByDate(times.getJavaDate());
            periodName = period.getPeriodName();
        }
        
        //页面属性设置
        model.addAttribute("periodName", periodName);

        
        return "gLTable/alBalance";
    }
    
    
    
    /**
     * 
     * @description 资产负债表获取json数据
     * @date 2021年2月9日
     * @author dongbin
     * @param model
     * @return
     * @return String
     *
     */
    @RequestMapping("getGLALBalanceTableJson")
    @ResponseBody
    public String getGLALBalanceTableJson(String periodName, Model model) {
        
        String json = "[{"
                + "'name': '资产负债表',"
                + "'index': 0,"
                + "'status': 1,'order': 0,"
                + "'defaultColWidth': 100,"
                + "'config': {"
                + "'merge':{},"
                + "'rowlen':{}, "
                + "'columnlen':{'0': 300, '2': 150, '3': 400, '5': 150}, "
                + "},"
                + "'celldata': ["
                + "{'r':0,'c':0,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'资产','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':0,'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'期末余额','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':0,'c':2,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'上年年末余额','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':0,'c':3,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'负债或所有者权益（或股东权益）','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':0,'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'期末余额','ct':{'fa':'General','t':'s'},'m':''}},"
                + "{'r':0,'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':'上年年末余额','ct':{'fa':'General','t':'s'},'m':''}},";

        
        //一级科目map
        Map<String, BigDecimal[]> balanceMap = new HashMap<String, BigDecimal[]>();
        //获取主分类账
        GLLedger glLedger = this.glLedgerService.getPrimaryGLLedgerByLegal(ShiroUtil.getLegalCode());
        //获取一级科目
        List<MdFinanceSubject> subjectList = this.mdFinanceSubjectService.getMdFinanceSubjectListByGrade(2);
        //获取科目在主分类账中的段值位置
        int segmentNum = this.glLedgerService.getSegmentNumByLegal(ShiroUtil.getLegalCode(), "SEGMENT_SUBJECT");

        //循环获取每个一级科目的所有下级科目
        for(MdFinanceSubject subject: subjectList) {
            //年度期初借方贷方
            BigDecimal beginYearDr = new BigDecimal(0D);
            BigDecimal beginYearCr = new BigDecimal(0D);
            //期初借方贷方
            BigDecimal beginDr = new BigDecimal(0D);
            BigDecimal beginCr = new BigDecimal(0D);
            //本期发生借方贷方
            BigDecimal periodDr = new BigDecimal(0D);
            BigDecimal periodCr = new BigDecimal(0D);
            //期末借方贷方
            BigDecimal endDr = new BigDecimal(0D);
            BigDecimal endCr = new BigDecimal(0D);
            
            List<GLCodeCombinations> glCodeCombinations = this.glCodeCombinationsService.getGLCodeCombinationsBySegmentValue(String.valueOf(segmentNum), subject.getSubjectCode(), true);
            
            //获取年度期初
            Times times = new Times();
            times.getDate();
            for(int a=0;a<glCodeCombinations.size();a++) {
                List<GLBalance> glBalanceList = this.gLBalanceService.getGLBalanceListBySubject(glLedger.getLedgerCode(), times.year+"-01", glCodeCombinations.get(a).getCodeCombinationCode());
                //循环计算期初
                for(int b=0;b<glBalanceList.size();b++) {
                    //累加期初
                    if(b==0) {
                        beginYearDr = new BigDecimal(glBalanceList.get(b).getBeginDr()).add(beginYearDr);
                        beginYearCr = new BigDecimal(glBalanceList.get(b).getBeginCr()).add(beginYearCr);
                        break;
                    }
                }
            }
            
            //循环所有下级科目获取下级科目的平衡表   
            for(int a=0;a<glCodeCombinations.size();a++) {
                List<GLBalance> glBalanceList = this.gLBalanceService.getGLBalanceListBySubject(glLedger.getLedgerCode(), periodName, glCodeCombinations.get(a).getCodeCombinationCode());
                //循环计算科目余额表
                for(int b=0;b<glBalanceList.size();b++) {
                    //累加期初
                    if(b==0) {
                        beginDr = new BigDecimal(glBalanceList.get(b).getBeginDr()).add(beginDr);
                        beginCr = new BigDecimal(glBalanceList.get(b).getBeginCr()).add(beginCr);
                    }
                    //累加本期发生
                    periodDr = new BigDecimal(glBalanceList.get(b).getPeriodDr()).add(periodDr);
                    periodCr = new BigDecimal(glBalanceList.get(b).getPeriodCr()).add(periodCr);
                }
            }
            //累加期末
            endDr = beginDr.add(periodDr);
            endCr = beginCr.add(periodCr);
            
            //重新计算年度期初借贷方
            BigDecimal beginYearSum = new BigDecimal(0D);
            if(beginYearDr.doubleValue()>=beginYearCr.doubleValue()) {
                beginYearSum = beginYearDr.subtract(beginYearCr);
            }else {
                beginYearSum = beginYearCr.subtract(beginYearDr);
            }
            
            //重新计算期末借贷方
            BigDecimal endSum = new BigDecimal(0D);
            if(endDr.doubleValue()>=endCr.doubleValue()) {
                endSum = endDr.subtract(endCr);
            }else {
                endSum = endCr.subtract(endDr);
            }
            
            //设置map值
            balanceMap.put(subject.getSubjectName(), new BigDecimal[] {endSum, beginYearSum});
        }
        
        //组合json
        //line1
        json = json + "{'r':1,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'流动资产：','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':1,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':1,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':1,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'流动负债：','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':1,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':1,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        
        //line2
        Double[] hbzj = this.getSubjectBalanceSum(balanceMap, new String[] {"库存现金","银行存款"}, new String[] {});
        Double[] dqjk = this.getSubjectBalanceSum(balanceMap, new String[] {"短期借款"}, new String[] {});
        json = json + "{'r':2,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        货币资金','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':2,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+hbzj[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':2,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+hbzj[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':2,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        短期借款','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':2,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+dqjk[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':2,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+dqjk[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line3
        Double[] jyxjrzc = this.getSubjectBalanceSum(balanceMap, new String[] {"交易性金融资产"}, new String[] {});
        Double[] jyxjrfz = this.getSubjectBalanceSum(balanceMap, new String[] {"交易性金融负债"}, new String[] {});
        json = json + "{'r':3,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        交易性金融资产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':3,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+jyxjrzc[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':3,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+jyxjrzc[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':3,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        交易性金融负债','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':3,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+jyxjrfz[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':3,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+jyxjrfz[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line4
        Double[] yspj = this.getSubjectBalanceSum(balanceMap, new String[] {"应收票据"}, new String[] {});
        Double[] yfpj = this.getSubjectBalanceSum(balanceMap, new String[] {"应付票据"}, new String[] {});
        json = json + "{'r':4,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        应收票据','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':4,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yspj[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':4,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yspj[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':4,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        应付票据','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':4,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yfpj[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':4,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yfpj[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line5
        Double[] yszk = this.getSubjectBalanceSum(balanceMap, new String[] {"应收账款"}, new String[] {});
        Double[] yfzk = this.getSubjectBalanceSum(balanceMap, new String[] {"应付账款"}, new String[] {});
        json = json + "{'r':5,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        应收账款','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':5,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yszk[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':5,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yszk[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':5,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        应付账款','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':5,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yfzk[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':5,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yfzk[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line6
        Double[] yf = this.getSubjectBalanceSum(balanceMap, new String[] {"预付账款"}, new String[] {});
        Double[] ys = this.getSubjectBalanceSum(balanceMap, new String[] {"预收账款"}, new String[] {});
        json = json + "{'r':6,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        预付账款','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':6,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yf[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':6,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yf[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':6,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        预收账款','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':6,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+ys[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':6,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+ys[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line7
        Double[] qtysk = this.getSubjectBalanceSum(balanceMap, new String[] {"其他应收款"}, new String[] {});
        Double[] yfzgxc = this.getSubjectBalanceSum(balanceMap, new String[] {"应付职工薪酬"}, new String[] {});
        json = json + "{'r':7,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        其他应收款','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':7,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+qtysk[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':7,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+qtysk[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':7,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        应付职工薪酬','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':7,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yfzgxc[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':7,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yfzgxc[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line8
        Double[] ch = this.getSubjectBalanceSum(balanceMap, new String[] {"材料采购", "原材料", "发出商品", "库存商品", "周转材料", "委托加工物资", "生产成本"}, new String[] {"存货跌价准备"});
        Double[] yjsf = this.getSubjectBalanceSum(balanceMap, new String[] {"应交税费"}, new String[] {});
        json = json + "{'r':8,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        存货','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':8,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+ch[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':8,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+ch[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':8,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        应交税费','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':8,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yjsf[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':8,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yjsf[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line9
        //=============================================持有待售资产 未生效
        Double[] qtyfk = this.getSubjectBalanceSum(balanceMap, new String[] {"其他应付款"}, new String[] {});
        json = json + "{'r':9,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        持有待售资产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':9,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':9,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':9,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        其他应付款','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':9,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+qtyfk[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':9,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+qtyfk[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line10
        //=============================================一年内到期的非流动资产 未生效
        //=============================================持有待售负债 未生效
        json = json + "{'r':10,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        一年内到期的非流动资产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':10,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':10,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':10,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        持有待售负债','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':10,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':10,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line11
        //=============================================其他流动资产 未生效
        //=============================================一年内到期的非流动负债 未生效
        json = json + "{'r':11,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        其他流动资产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':11,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':11,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':11,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        一年内到期的非流动负债','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':11,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':11,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line12
        Double ldzchj1 = new BigDecimal(hbzj[0]).add(new BigDecimal(jyxjrzc[0])).add(new BigDecimal(yspj[0])).add(new BigDecimal(yszk[0])).add(new BigDecimal(yf[0])).add(new BigDecimal(qtysk[0])).add(new BigDecimal(ch[0])).doubleValue();
        Double ldzchj2 = new BigDecimal(hbzj[1]).add(new BigDecimal(jyxjrzc[1])).add(new BigDecimal(yspj[1])).add(new BigDecimal(yszk[1])).add(new BigDecimal(yf[1])).add(new BigDecimal(qtysk[1])).add(new BigDecimal(ch[1])).doubleValue();
        //=============================================其他流动负债 未生效
        json = json + "{'r':12,'c':0,'v':{'bl':1,'fs':12,'ht':1,'vt':0,'v':'                流动资产合计','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':12,'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+ldzchj1+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':12,'c':2,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+ldzchj2+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':12,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        其他流动负债','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':12,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':12,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line13
        Double ldfzhj1 = new BigDecimal(dqjk[0]).add(new BigDecimal(jyxjrfz[0])).add(new BigDecimal(yfpj[0])).add(new BigDecimal(yfzk[0])).add(new BigDecimal(ys[0])).add(new BigDecimal(yfzgxc[0])).add(new BigDecimal(yjsf[0])).add(new BigDecimal(qtyfk[0])).doubleValue();
        Double ldfzhj2 = new BigDecimal(dqjk[1]).add(new BigDecimal(jyxjrfz[1])).add(new BigDecimal(yfpj[1])).add(new BigDecimal(yfzk[1])).add(new BigDecimal(ys[1])).add(new BigDecimal(yfzgxc[1])).add(new BigDecimal(yjsf[1])).add(new BigDecimal(qtyfk[1])).doubleValue();
        json = json + "{'r':13,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'非流动资产：','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':13,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':13,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':13,'c':3,'v':{'bl':1,'fs':12,'ht':1,'vt':0,'v':'                流动负债合计','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':13,'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+ldfzhj1+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':13,'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+ldfzhj2+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line14
        Double[] kgcsjrzc = this.getSubjectBalanceSum(balanceMap, new String[] {"可供出售金融资产"}, new String[] {});
        json = json + "{'r':14,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        可供出售金融资产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':14,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+kgcsjrzc[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':14,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+kgcsjrzc[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':14,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'非流动负债： ','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':14,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':14,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line15
        Double[] cyzdqtz = this.getSubjectBalanceSum(balanceMap, new String[] {"持有至到期投资"}, new String[] {"持有至到期投资减值准备"});
        Double[] cqjk = this.getSubjectBalanceSum(balanceMap, new String[] {"长期借款"}, new String[] {});
        json = json + "{'r':15,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        持有至到期投资','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':15,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cyzdqtz[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':15,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cyzdqtz[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':15,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        长期借款','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':15,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cqjk[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':15,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cqjk[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line16
        Double[] cqysk = this.getSubjectBalanceSum(balanceMap, new String[] {"长期应收款"}, new String[] {});
        //=============================================应付债券 未生效
        json = json + "{'r':16,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        长期应收款','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':16,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cqysk[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':16,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cqysk[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':16,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        应付债券','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':16,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':16,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line17
        Double[] cqgqtz = this.getSubjectBalanceSum(balanceMap, new String[] {"长期股权投资"}, new String[] {"长期股权投资减值准备"});
        //=============================================优先股 未生效
        json = json + "{'r':17,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        长期股权投资','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':17,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cqgqtz[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':17,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cqgqtz[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':17,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'                其中：优先股','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':17,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':17,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line18
        Double[] tzxfdc = this.getSubjectBalanceSum(balanceMap, new String[] {"投资性房地产"}, new String[] {});
        //=============================================永续债 未生效
        json = json + "{'r':18,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        投资性房地产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':18,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+tzxfdc[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':18,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+tzxfdc[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':18,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'                            永续债','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':18,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':18,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line19
        Double[] gdzc = this.getSubjectBalanceSum(balanceMap, new String[] {"固定资产", "固定资产清理"}, new String[] {"累计折旧", "固定资产减值准备"});
        Double[] cqyfk = this.getSubjectBalanceSum(balanceMap, new String[] {"长期应付款"}, new String[] {"未确认融资费用"});
        json = json + "{'r':19,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        固定资产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':19,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+gdzc[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':19,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+gdzc[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':19,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        长期应付款','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':19,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cqyfk[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':19,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cqyfk[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line20
        Double[] gcwz = this.getSubjectBalanceSum(balanceMap, new String[] {"在建工程", "工程物资"}, new String[] {});
        Double[] yjfz = this.getSubjectBalanceSum(balanceMap, new String[] {"预计负债"}, new String[] {});
        json = json + "{'r':20,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        在建工程','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':20,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+gcwz[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':20,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+gcwz[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':20,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        预计负债','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':20,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yjfz[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':20,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yjfz[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line21
        Double[] scxswzc = this.getSubjectBalanceSum(balanceMap, new String[] {"生产性生物资产"}, new String[] {"生产性生物资产累计折旧"});
        Double[] dysy = this.getSubjectBalanceSum(balanceMap, new String[] {"递延收益"}, new String[] {});
        json = json + "{'r':21,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        生产性生物资产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':21,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+scxswzc[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':21,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+scxswzc[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':21,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        递延收益','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':21,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+dysy[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':21,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+dysy[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line22
        Double[] yqzc = this.getSubjectBalanceSum(balanceMap, new String[] {"油气资产"}, new String[] {"累计折耗"});
        Double[] dysdsfz = this.getSubjectBalanceSum(balanceMap, new String[] {"递延所得税负债"}, new String[] {});
        json = json + "{'r':22,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        油气资产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':22,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yqzc[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':22,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yqzc[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':22,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        递延所得税负债','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':22,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+dysdsfz[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':22,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+dysdsfz[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line23
        Double[] wxzc = this.getSubjectBalanceSum(balanceMap, new String[] {"无形资产"}, new String[] {"累计摊销", "无形资产减值准备"});
        //=============================================其他非流动负债 未生效
        json = json + "{'r':23,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        无形资产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':23,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+wxzc[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':23,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+wxzc[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':23,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        其他非流动负债','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':23,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':23,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line24
        Double[] yfzs = this.getSubjectBalanceSum(balanceMap, new String[] {"研发支出"}, new String[] {});
        Double fldfzhj1 = new BigDecimal(cqjk[0]).add(new BigDecimal(cqyfk[0])).add(new BigDecimal(yjfz[0])).add(new BigDecimal(dysy[0])).add(new BigDecimal(dysdsfz[0])).doubleValue();
        Double fldfzhj2 = new BigDecimal(cqjk[1]).add(new BigDecimal(cqyfk[1])).add(new BigDecimal(yjfz[1])).add(new BigDecimal(dysy[1])).add(new BigDecimal(dysdsfz[1])).doubleValue();
        json = json + "{'r':24,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        开发支出','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':24,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yfzs[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':24,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yfzs[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':24,'c':3,'v':{'bl':1,'fs':12,'ht':1,'vt':0,'v':'                非流动负债合计','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':24,'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+fldfzhj1+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':24,'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+fldfzhj2+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line25
        Double[] sy = this.getSubjectBalanceSum(balanceMap, new String[] {"商誉"}, new String[] {});
        Double fzhj1 = new BigDecimal(ldfzhj1).add(new BigDecimal(fldfzhj1)).doubleValue();
        Double fzhj2 = new BigDecimal(ldfzhj2).add(new BigDecimal(fldfzhj2)).doubleValue();
        json = json + "{'r':25,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        商誉','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':25,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+sy[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':25,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+sy[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':25,'c':3,'v':{'bl':1,'fs':12,'ht':1,'vt':0,'v':'                        负债合计','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':25,'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+fzhj1+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':25,'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+fzhj2+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line26
        Double[] cqdtfy = this.getSubjectBalanceSum(balanceMap, new String[] {"长期待摊费用"}, new String[] {});
        json = json + "{'r':26,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        长期待摊费用','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':26,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cqdtfy[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':26,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+cqdtfy[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':26,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'所有者权益（或股东权益）：','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':26,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':26,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line27
        Double[] dysdszc = this.getSubjectBalanceSum(balanceMap, new String[] {"递延所得税资产"}, new String[] {});
        Double[] sszb = this.getSubjectBalanceSum(balanceMap, new String[] {"实收资本"}, new String[] {});
        json = json + "{'r':27,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        递延所得税资产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':27,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+dysdszc[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':27,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+dysdszc[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':27,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        实收资本（或股本）','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':27,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+sszb[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':27,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+sszb[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line28
        //=============================================其他非流动资产 未生效
        //=============================================其他权益工具 未生效
        json = json + "{'r':28,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        其他非流动资产','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':28,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':28,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':28,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        其他权益工具','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':28,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':28,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line29
        Double fldzchj1 = new BigDecimal(kgcsjrzc[0]).add(new BigDecimal(cyzdqtz[0])).add(new BigDecimal(cqysk[0])).add(new BigDecimal(cqgqtz[0])).add(new BigDecimal(tzxfdc[0])).add(new BigDecimal(gdzc[0])).add(new BigDecimal(gcwz[0])).add(new BigDecimal(scxswzc[0])).add(new BigDecimal(yqzc[0])).add(new BigDecimal(wxzc[0])).add(new BigDecimal(yfzs[0])).add(new BigDecimal(sy[0])).add(new BigDecimal(cqdtfy[0])).add(new BigDecimal(dysdszc[0])).doubleValue();
        Double fldzchj2 = new BigDecimal(kgcsjrzc[1]).add(new BigDecimal(cyzdqtz[1])).add(new BigDecimal(cqysk[1])).add(new BigDecimal(cqgqtz[1])).add(new BigDecimal(tzxfdc[1])).add(new BigDecimal(gdzc[1])).add(new BigDecimal(gcwz[1])).add(new BigDecimal(scxswzc[1])).add(new BigDecimal(yqzc[1])).add(new BigDecimal(wxzc[1])).add(new BigDecimal(yfzs[1])).add(new BigDecimal(sy[1])).add(new BigDecimal(cqdtfy[1])).add(new BigDecimal(dysdszc[1])).doubleValue();
        //=============================================优先股 未生效
        json = json + "{'r':29,'c':0,'v':{'bl':1,'fs':12,'ht':1,'vt':0,'v':'                非流动资产合计','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':29,'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+fldzchj1+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':29,'c':2,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+fldzchj2+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':29,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'                其中：优先股','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':29,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':29,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line30
        //=============================================永续债 未生效
        json = json + "{'r':30,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':30,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':30,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':30,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'                           永续债','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':30,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':30,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line31
        Double[] zbgj = this.getSubjectBalanceSum(balanceMap, new String[] {"资本公积"}, new String[] {});
        json = json + "{'r':31,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':31,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':31,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':31,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        资本公积','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':31,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+zbgj[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':31,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+zbgj[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line32
        Double[] kcg = this.getSubjectBalanceSum(balanceMap, new String[] {"库存股"}, new String[] {});
        json = json + "{'r':32,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':32,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':32,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':32,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        减：库存股','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':32,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+kcg[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':32,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+kcg[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line33
        //=============================================其他综合收益 未生效
        json = json + "{'r':33,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':33,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':33,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':33,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        其他综合收益','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':33,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':33,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line34
        //=============================================专项储备 未生效
        json = json + "{'r':34,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':34,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':34,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':34,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        专项储备','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':34,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':34,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line35
        Double[] yygj = this.getSubjectBalanceSum(balanceMap, new String[] {"盈余公积"}, new String[] {});
        json = json + "{'r':35,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':35,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':35,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':35,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        盈余公积','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':35,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yygj[0]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':35,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':"+yygj[1]+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line36
        //=============================================未分配利润 未生效
        json = json + "{'r':36,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':36,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':36,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':36,'c':3,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'        未分配利润','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':36,'c':4,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':36,'c':5,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line37
        Double syzqyhj1 = new BigDecimal(sszb[0]).add(new BigDecimal(zbgj[0])).add(new BigDecimal(yygj[0])).subtract(new BigDecimal(kcg[0])).doubleValue();
        Double syzqyhj2 = new BigDecimal(sszb[1]).add(new BigDecimal(zbgj[1])).add(new BigDecimal(yygj[1])).subtract(new BigDecimal(kcg[1])).doubleValue();
        json = json + "{'r':37,'c':0,'v':{'bl':0,'fs':12,'ht':1,'vt':0,'v':'','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':37,'c':1,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':37,'c':2,'v':{'bl':0,'fs':12,'ht':0,'vt':0,'v':0,'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':37,'c':3,'v':{'bl':1,'fs':12,'ht':1,'vt':0,'v':'                所有者权益（或股东权益）合计','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':37,'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+syzqyhj1+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':37,'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+syzqyhj2+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        //line38
        Double zczj1 = new BigDecimal(ldzchj1).add(new BigDecimal(fldzchj1)).doubleValue();
        Double zczj2 = new BigDecimal(ldzchj2).add(new BigDecimal(fldzchj2)).doubleValue();
        Double fzhsyzqy1 = new BigDecimal(fzhj1).add(new BigDecimal(syzqyhj1)).doubleValue();
        Double fzhsyzqy2 = new BigDecimal(fzhj2).add(new BigDecimal(syzqyhj2)).doubleValue();
        json = json + "{'r':38,'c':0,'v':{'bl':1,'fs':12,'ht':1,'vt':0,'v':'                        资产总计','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':38,'c':1,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+zczj1+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':38,'c':2,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+zczj2+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':38,'c':3,'v':{'bl':1,'fs':12,'ht':1,'vt':0,'v':'                        负债和所有者权益（或股东权益）总计','ct':{'fa':'General','t':'s'},'m':''}},";
        json = json + "{'r':38,'c':4,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+fzhsyzqy1+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        json = json + "{'r':38,'c':5,'v':{'bl':1,'fs':12,'ht':0,'vt':0,'v':"+fzhsyzqy2+",'ct':{'fa':'#,##0.00','t':'n'},'m':''}},";
        
        
        json = json + "], ";
        json = json + "}]";
        
        return json;
    }
    
    //根据一级科目的科目余额map获取多科目的汇总值
    private Double[] getSubjectBalanceSum(Map<String, BigDecimal[]> balanceMap, String[] addSubjects, String[] subSubjects) {
        BigDecimal beginYearSum = new BigDecimal(0D);
        BigDecimal endSum = new BigDecimal(0D);
        //循环要加的科目
        for(String subject: addSubjects) {
            try {
                endSum = endSum.add(balanceMap.get(subject)[0]);
                beginYearSum = beginYearSum.add(balanceMap.get(subject)[1]);
                //System.out.println("############==="+balanceMap.get(subject)[0]);
                //System.out.println("############==="+balanceMap.get(subject)[1]);
            }catch(Exception e) {
            }
        }
        
        //循环要减的科目
        for(String subject: subSubjects) {
            try {
                endSum = endSum.subtract(balanceMap.get(subject)[0]);
                beginYearSum = beginYearSum.subtract(balanceMap.get(subject)[1]);
                //System.out.println("############==="+balanceMap.get(subject)[0]);
                //System.out.println("############==="+balanceMap.get(subject)[1]);
            }catch(Exception e) {
            }
        }
        
        return new Double[] {endSum.doubleValue(), beginYearSum.doubleValue()};
    }
}
